class Paginator:
    def __init__(self, items, page=1, per_page=5):
        """
        初始化分页器
        :param items: 需要分页的数据列表
        :param page: 当前页码
        :param per_page: 每页显示的条数
        """
        self.items = items
        self.page = page
        self.per_page = per_page
        self.total = len(items)
        self.pages = (self.total + per_page - 1) // per_page

        start_idx = (page - 1) * per_page
        end_idx = start_idx + per_page
        self.current_items = items[start_idx:end_idx]

        # 分页属性
        self.has_prev = page > 1
        self.has_next = end_idx < self.total
        self.prev_num = page - 1
        self.next_num = page + 1

    def iter_pages(self, left_edge=2, left_current=2, right_current=2, right_edge=2):
        """
        生成页码范围
        """
        last = 0
        for num in range(1, self.pages + 1):
            if (num <= left_edge
                    or (self.page - left_current - 1 < num < self.page + right_current)
                    or num > self.pages - right_edge):
                if last + 1 != num:
                    yield None
                yield num
                last = num

    @property
    def items_for_page(self):
        """
        返回当前页的数据
        """
        return self.current_items
